package com.gcsoftware.web.test;

import com.baomidou.mybatisplus.toolkit.StringUtils;
import com.gcsoftware.web.test.entity.UserInfo;
import com.gcsoftware.web.response.ResultRsp;
import com.gcsoftware.web.test.service.UserService;
import com.gcsoftware.web.utils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.spring.web.readers.parameter.ParameterTypeReader;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qs on 2018/4/16.
 */
@Api(value = "gaff-admin示范用相关接口")
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping("/list")
    @ApiOperation(value = "查询用户列表")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType= "path", name = "userName", value = "用户名称", required = false, dataType = "String")
    })
    public ResultRsp<List> queryForList(@RequestParam(value = "userName" ,required = false) String userName) throws Exception {
       /* UserInfo user = null;
        try {
            System.out.println(user.getLoginName());
        } catch (Exception e) {
            throw new GaffException(500,"user is null");
        }*/
        UserInfo info = null;
        if (StringUtils.isNotEmpty(userName)) {
           info = new UserInfo();
           info.setUserName(userName);
       }
        return ResultUtils.success(userService.findList(userName));
    }
    @GetMapping("/one")
    public ResultRsp<UserInfo> getOne(String id, String loginName, String userEmail) {
        return ResultUtils.success(userService.get(id,loginName,userEmail));
    }

    @GetMapping("/add")
    public UserInfo saveUser() {
        UserInfo userInfo = new UserInfo();
        userInfo.setLoginPwd("abccc4");
        userInfo.setLoginName("gaff4");
        userInfo.setLoginPwdSalt("asdfdsfasd4");
        userInfo.setUserEmail("email4");
        userInfo.setUserName("zhangsan4");
       return userService.insert(userInfo);
    }
}
